#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
script name: views
Created on 2020/1/2 14:56 by PyCharm
@author: fujianjian
"""
from datetime import datetime

from flask_login import login_required, current_user

from . import main
from .forms import NameForm
from flask import redirect, url_for, render_template, session


@main.route('/', methods=['GET', 'POST'])
def index():
    form = NameForm()
    if form.validate_on_submit():
        return redirect(url_for('.index'))
    return render_template('index.html', form=form,
                           name=session.get('name'),
                           current_user=current_user,
                           known=session.get('known', False),
                           current_time=datetime.utcnow())


@login_required
@main.route('/userinfo', methods=['get', 'post'])
def userinfo():
    return 'only authenticated user are allowed!'
